package com.heima.jopo.servlet;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.web.SeleList;
import com.heima.jopo.web.Updatexg;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name="niubi2",urlPatterns = "/date2")
public class UpdaServlet_2 extends  HttpServlet{

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        //获取WEB前段输入的值
        String zh = request.getParameter("zh");
        String passwrod = request.getParameter("pwd");
        String username = request.getParameter("username");
        String sex = request.getParameter("sex");
        String year = request.getParameter("year");
        String mounth = request.getParameter("mounth");
        String day = request.getParameter("day");

        String id = request.getParameter("pid");

        String dayth = "" + year + "-" + mounth + "-" + day;
        String now = request.getParameter("now");

        UserInfo userInfo=new UserInfo();
        //给属性初始化值
        userInfo.setPhone(zh);
        userInfo.setPasswrod(passwrod);
        userInfo.setUsername(username);
        userInfo.setSex(sex);
        userInfo.setBirthday(dayth);
        userInfo.setCareer(now);
        userInfo.setId(id);

        Updatexg up=new Updatexg();
            //修改完的SQL
        up.update(userInfo,id);




        //再查询出所有的对象信息
        SeleList seleList=new SeleList();
        List<UserInfo> listuser = seleList.listuser();

        HttpSession session = request.getSession();
        session.setAttribute("seleUser",listuser);
        //然后进行到主页跳转
//        request.getRequestDispatcher("main.jsp").forward(request,response);
        response.sendRedirect("main.jsp");
    }
}
